package lq3823;

import java.util.*;

public class Main {
	// 地图边界
	private static final int N = 1000 + 10;
	// 步数偏移量
	private static final int[] dx = { -1, 0, 1, 0 };
	private static final int[] dy = { 0, 1, 0, -1 };

	private static int n, m, k;
	private static int A, B, C, D;
	private static char[][] g = new char[N][N];
	// 到每个点的最短步数
	private static int[][] dist = new int[N][N];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] lineArr = sc.nextLine().split(" ");
		n = Integer.parseInt(lineArr[0]);
		m = Integer.parseInt(lineArr[1]);

		lineArr = sc.nextLine().split(" ");
		A = Integer.parseInt(lineArr[0]) - 1;
		B = Integer.parseInt(lineArr[1]) - 1;
		C = Integer.parseInt(lineArr[2]) - 1;
		D = Integer.parseInt(lineArr[3]) - 1;

		for (int i = 0; i < n; ++i)
			g[i] = sc.nextLine().toCharArray();

		k = Integer.parseInt(sc.nextLine());

		// bfs模板计算到每个点的最少步数
		int d = bfs();

		if (d == Integer.MIN_VALUE) {
			System.out.println("-1");
			return;
		}

		int res = d / k;
		d %= k;

		if (d == 0)
			System.out.println(res);
		else if (k % 2 == 0) {
			if (d % 2 == 0)
				System.out.println(res + 1);
			else
				System.out.println("-1");
		} else {
			if (d % 2 == 0)
				System.out.println(res + 2);
			else
				System.out.println(res + 1);
		}
	}

	private static int bfs() {
		// 队列里面放长度为2的数组表示坐标
		Queue<int[]> q = new LinkedList<>();
		// 起始点坐标
		q.add(new int[] { A, B });

		// 用最小整数（表示无法到达）填充数组
		for (int i = 0; i < n; ++i)
			Arrays.fill(dist[i], Integer.MIN_VALUE);
		// 起点0步可达
		dist[A][B] = 0;

		while (!q.isEmpty()) {
			int[] t = q.poll();

			for (int i = 0; i < 4; ++i) {
				int tx = t[0] + dx[i], ty = t[1] + dy[i];
				if (tx < 0 || ty < 0 || tx >= n || ty >= m || g[tx][ty] == '#' || dist[tx][ty] != Integer.MIN_VALUE)
					continue;
				dist[tx][ty] = dist[t[0]][t[1]] + 1;
				q.add(new int[] { tx, ty });
			}
		}

		// 返回到终点的步数
		return dist[C][D];
	}
}
